package com.xxl.job.executor.sjbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.executor.sjbank.pojo.FiStopcall;
import com.xxl.job.executor.sjbank.service.FiStopcallService;
import com.xxl.job.executor.sjbank.mapper.FiStopcallMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author tsu
 * @description 针对表【fi_stopcall(号码停催表)】的数据库操作Service实现
 * @createDate 2024-04-21 21:46:34
 */
@Service
public class FiStopcallServiceImpl extends ServiceImpl<FiStopcallMapper, FiStopcall>
        implements FiStopcallService {

    @Override
    public void stopCall() {
        List<FiStopcall> list = list(new QueryWrapper<FiStopcall>()
                .eq("status", 2)
                .le("stopenddt", LocalDateTime.now()));

        XxlJobHelper.log("XXL-JOB stopCall list.size:" + list.size() + "条");

        list.forEach(x -> {
            x.setStatus(5);
            x.setCloseusr("system");
            x.setClosedt(new Date());
            x.setClosedsc("自动终止停催");
            updateById(x);
            if (Objects.equals(x.getStoptype(), "CASE")) {
                XxlJobHelper.log("XXL-JOB stopCall stopkey:" + x.getStopkey());
                baseMapper.stopCase(Integer.parseInt(x.getStopkey()));
            }
        });
    }
}




